#ifndef _CONVERSATIONCONECTOR_H
#define _CONVERSATIONCONECTOR_H

#include <QTcpSocket>
#include "packet.h"

class ConversationConector {
  public:
    ConversationConector(QTcpSocket *socket);
    ~ConversationConector();
    void CloseConnection();

    bool isActive();

    //It is called from the TCP socket. Reads all the data in the TCP socket buffer and concatenates it in it's own buffer.
    void dataReception();

    //Sends packet throught the socket.
    int sendPacket(Packet *packet);

    //Decodes the first full packet from the buffer. Returns null if there isn't one.
    Packet *getPacket();

  private:
    //Bytes directly received from the TCP socket. They are cleaned as soon as full packets are extracted.
    QByteArray *buffer;

    //The socket this class manages.
    QTcpSocket *socket;

};
#endif
